package xddq

import (
	"fmt"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

func (xd *XdDriver) CheckUserBagInfoData(allInfo []D.UserBagInfo) {
	flag := false
	needTake := true
	for _, info := range allInfo {
		needTake = false
		flag = false
		if info.ID == "A08D06" {
			xd.UserData.ChopDownTree.XianNum = info.Num //获取仙玉的数量
		} else if info.ID == "A38D06" {
			xd.UserData.ChopDownTree.StoneNum = info.Num //获取灵石的数量
		} else if info.ID == "A48D06" {
			xd.UserData.ChopDownTree.PeachNum = info.Num //获取仙桃的数量
		} else if info.ID == "A68D06" {
			xd.UserData.ChopDownTree.WusheShiNum = info.Num //五色石数量
		} else if info.ID == "A78D06" {
			xd.UserData.ChopDownTree.SpiritualGrassNum = info.Num //先天灵草数量
		} else if info.ID == "A88D06" {
			xd.UserData.ChopDownTree.LingZhiNum = info.Num //万年灵芝数量
			if info.Num > 254 {
				info.Num = 254
			}
			xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_TALENT_READ_BOOK, fmt.Sprintf("08%02X", info.Num)))
		} else if info.ID == "A98D06" {
			xd.UserData.ChopDownTree.Res = info.Num
		} else if info.ID == "AC8D06" {
			flag = true
		} else if info.ID == "B08D06" {
			xd.UserData.ChopDownTree.DaoShuNum = info.Num //道书数量
		} else if info.ID == "B78D06" {
			xd.UserData.ChopDownTree.Res = info.Num
		} else if info.ID == "B98D06" {
			xd.UserData.ChopDownTree.PingNum = info.Num //净瓶水数量
			flag = true
		} else if info.ID == "BA8D06" {
			xd.UserData.ChopDownTree.ChallengeCouponNum = info.Num //挑战券数量
			flag = true
			if info.Num > 0 {
				xd.UserData.FightInfo.ChallengeCoupon <- 1
			}
		} else if info.ID == "CC8D06" {
			xd.UserData.ChopDownTree.TianYanLingNum = info.Num //天衍令数量
		} else if info.ID == "CE8D06" {
			xd.UserData.ChopDownTree.HeroRakingScore = info.Num //群英榜积分
		} else if info.ID == "D38D06" { //传说塑魂花碎片
			if (info.Num / 20) > 0 {
				go func() {
					xd.waitForStartSendCmd()
					go xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_BAG_COMPOUND_PROP, "08 92 4E 12 01 31"))
				}()
			}
			//} else if info.ID == "D38D06" { //神话塑魂花碎片
			//	if (info.Num / 20) > 0 {
			//		go xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_BAG_COMPOUND_PROP, "08 92 4E 12 01 31"))
			//	}
			//} else if info.ID == "B88E06" { //天宫图纸
		} else if info.ID == "E98D06" {
			xd.UserData.ChopDownTree.LingQiNum = info.Num //灵气数量
		} else if info.ID == "F18D06" {
			xd.UserData.ChopDownTree.WuDaoStoneNum = info.Num //悟道石数量
		} else if info.ID == "858E06" {
			xd.UserData.ChopDownTree.XuanHuangGuoNum = info.Num //玄黄果数量
		} else if info.ID == "C88E06" { //天宫图纸碎片
			if (info.Num / 20) > 0 {
				go func() {
					xd.waitForStartSendCmd()
					xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_BAG_COMPOUND_PROP, "08 B4 4E 12 01 31"))
				}()
			}
		} else if info.ID == "AD8E06" {
			xd.UserData.Xianju.PeachCoin = info.Num //桃妖币数量
		} else if info.ID == "D4B406" {
			xd.UserData.ChopDownTree.TengSheNum = info.Num //腾蛇信物数量
		} else if info.ID == "ADB406" {
			xd.UserData.WildOil = info.Num //蛮荒妖域剩余香油
		} else if info.ID == "E9B406" {
			xd.UserData.LongKuGrass = info.Num //龙窟秘境 龙须草数量
		} else if info.ID == "8DB506" {
			xd.UserData.CastSwordLiquid = info.Num //炼器大会 甘露仙液
		} else if info.ID == "E1B506" {
			xd.UserData.CondensingFragrance = info.Num //未央仙境 归元凝神香数量
		} else if info.ID == "C0B606" {
			xd.UserData.XIYOUGinsengFruit = info.Num //西游伏魔人参果
			//以下礼包需要自动开启
		} else if info.ID == "FF9309" { //随机传说灵兽
			needTake = true
		} else if info.ID == "B49409" { //琉璃珠礼包
			needTake = true
		} else if info.ID == "AC9409" { //随机炼化宝箱
			needTake = true
		} else if info.ID == "F79309" { //神话随机精怪碎片
			needTake = true
		} else if info.ID == "F89309" { //传说随机精怪碎片
			needTake = true
		} else if info.ID == "F99309" { //卓越随机精怪碎片
			needTake = true
		} else if info.ID == "FA9309" { //普通随机精怪碎片
			needTake = true
		} else if info.ID == "FB9309" { //常见随机精怪碎片
			needTake = true
		} else if info.ID == "829409" { //常见随机灵兽
			needTake = true
		} else if info.ID == "849409" { //游戏圈宝箱
			needTake = true
		} else if info.ID == "B19409" { //签到20天礼包
			needTake = true
		} else if info.ID == "B59409" { //先天灵草礼包
			needTake = true
		} else if info.ID == "B69409" { //御灵石礼包
			needTake = true
		} else if info.ID == "B79409" { //庚金礼包
			needTake = true
		} else if info.ID == "B89409" { //仙桃礼包
			needTake = true
		} else if info.ID == "91E209" { //自选炼化宝箱
			//needTake = true
			//para.Data += fmt.Sprintf("1A 09 0A 07 08 D8 8D 06 12 01 34")
		} else if info.ID == "B1CC0B" { //1-2级印记礼包
			needTake = true
		} else if info.ID == "B2CC0B" { //1-5级印记礼包
			needTake = true
		} else if info.ID == "B4CC0B" { //1级印记礼包
			needTake = true
		} else if info.ID == "C19A0C" { //随机灵感神通
			needTake = true
		} else if info.ID == "8ED30E" { //随机传说法宝碎片
			needTake = true
		} else if info.ID == "8FD30E" { //随机卓越法宝碎片
			needTake = true
		} else if info.ID == "90D30E" { //随机普通法宝碎片
			needTake = true
		} else if info.ID == "D7E20E" { //双域卓越法宝随机箱
			needTake = true
		} else if info.ID == "D8D911" { //随机稀有内丹碎片
			needTake = true
		} else if info.ID == "87C413" { //随机知玄玄诀碎片
			needTake = true
		} else if info.ID == "C7AE15" { //自选精良建筑碎片
			//	needTake = true
			//	para.Data += fmt.Sprintf("1A 0A 0A 08 08 91 E8 14 12 02 31 35")
		} else if info.ID == "C9AE15" { //随机建筑礼包
			needTake = true
		}
		/*碎片礼包 S_BAG_COMPOUND_PROP
		08 B1 4E 12 01 31 //太虚元石
		08 A7 4E 12 01 31 //随机传说灵兽
		*/
		if needTake && info.Num > 0 {
			go func() {
				xd.waitForStartSendCmd()
				xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_BAG_USE_PROP, info.Str))
			}()
		}
	}
	if flag {
		log.Infof("当前仙桃[%d] 净瓶水[%d] 仙玉[%s] 灵石[%s] 先天灵草[%d] 挑战券[%d] 玄黄果[%d] 灵气[%d] 万年灵芝[%d] 天衍令[%d] 腾蛇信物[%d] 五色石[%d] 群英榜积分[%d] 道书[%d] 悟道石[%d] 香油[%d]",
			xd.UserData.ChopDownTree.PeachNum, xd.UserData.ChopDownTree.PingNum, D.GetCombatValueDesc(int64(xd.UserData.ChopDownTree.XianNum)),
			D.GetCombatValueDesc(int64(xd.UserData.ChopDownTree.StoneNum)), xd.UserData.ChopDownTree.SpiritualGrassNum,
			xd.UserData.ChopDownTree.ChallengeCouponNum, xd.UserData.ChopDownTree.XuanHuangGuoNum, xd.UserData.ChopDownTree.LingQiNum,
			xd.UserData.ChopDownTree.LingZhiNum, xd.UserData.ChopDownTree.TianYanLingNum, xd.UserData.ChopDownTree.TengSheNum,
			xd.UserData.ChopDownTree.WusheShiNum, xd.UserData.ChopDownTree.HeroRakingScore, xd.UserData.ChopDownTree.DaoShuNum,
			xd.UserData.ChopDownTree.WuDaoStoneNum, xd.UserData.WildOil)
		if xd.UserData.ChopDownTree.XianNum > 20000 {
			task := xd.GetTaskByDesc("坊市-买100净瓶水")
			task.Enabled = true
		}
		//使用净瓶水
		if xd.UserData.ChopDownTree.PingNum > 100 {
			xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_ATTRIBUTE_DREAM_LV_UP_SPEED_UP, "08 02 10 64"))
		} else if xd.UserData.ChopDownTree.PingNum > 10 {
			xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_ATTRIBUTE_DREAM_LV_UP_SPEED_UP, "08 02 10 0A"))
		}
	}
}
